 # encoding: utf-8
class RequestAndComplaint::Complaint < ActiveRecord::Base
  belongs_to :obj_complaint_type, :class_name => 'RequestAndComplaint::ComplaintType', :foreign_key => 'complaint_type'
  belongs_to :obj_department, :class_name => 'Shared::Department', :foreign_key => 'department'
  belongs_to :obj_province, :class_name => 'Shared::Province', :foreign_key => 'province'
  belongs_to :obj_district, :class_name => 'Shared::District', :foreign_key => 'district'
  has_attached_file:avatar
  validates :description, :presence => {:message => "La descripcion es requerida"}

 validates :dni, :presence => {:message => "El DNI es requerido"}
   validates :dni, :length => { :is => 8, :message => "El DNI debe tener 8 caracteres de numeros" }


 validates :complaint_type, :presence => {:message => "El tipo de denuncia es requerido"}
 validates :email,:allow_blank => true, :format => {:with    => /^(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})$/i, :message => "El formato de E_mail no es correcto" }


  validates :phone, :allow_blank => true, :length => {:in => 7..9 }
   validates :department, :presence => {:message => "El departamento es requerido"}
   validates :province, :presence => {:message => "La provincia es requerida"}
   validates :district, :presence => {:message => "El distrito es requerido"}
   validates :address, :presence => {:message => "El direccion es requerido"}


  default_scope where("deleted = 0")

  def str_state
    if state == 0
      return "Registrada"
    end
    if state == 1
      return "Atendida"
    end
    if state == 2
      return "Omitida"
    end
    if state == 3
      return "Asignada"
    end

    
  end

  def id_type
      return id.to_s+" "+name
    end



  def self.list_states 
    
  return  [["Asignadas",3],["Atendidas",1],["Omitidas",2]]
  end

  def self.list_states_admin
      return  [["Registradas",0],["Asignadas",3],["Atendidas",1],["Omitidas",2]]
  end

end
